package com.oocl.heather.net;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import com.oocl.heather.util.Command;
import com.oocl.heather.util.CurrentFile;

public class NetServer {

	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException, ClassNotFoundException {
		// TODO Auto-generated method stub

		ServerSocket server=new ServerSocket(6666);
		Socket socket=server.accept();
		boolean flag=true;
		while(flag){
			InputStream is=socket.getInputStream();
			OutputStream os=socket.getOutputStream();
			
			//client send 
			
			Command command=new Command();
			do{
				
				BufferedReader br=new BufferedReader(new InputStreamReader(is));
				String line=br.readLine();
				System.out.println("Client says:"+line);
				
				
				File curren=new CurrentFile().currenfile();
				String result=command.getCommands(line,curren);
				os.write((result+"\r\n").getBytes());
				
				
			}while(true);
			
		}
		
	}

}
